﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace bai_tap
{
    class cphanso
    {
        int tu, mau;
        public cphanso()
        {
            tu = 0;
            mau = 1;
        }
        public cphanso(int x)
        {
            tu = x;
            mau = 1;
        }
        public cphanso(int t, int m)
        {
            this.tu = t;
            this.mau = m;
        }
        bool kiemtra()
        {
            return mau != 0;
        }
        //public void nhap(int tu,int mau)
        //{
        //nhaplai:
        //    Console.Write("nhap tu so:");
        //    tu = int.Parse(Console.ReadLine());
        //    Console.Write("nhap mau so:");
        //    mau = int.Parse(Console.ReadLine());
        //    if (!kiemtra())
        //        goto nhaplai;
        //}
        public void xuat()
        {
            Console.WriteLine("{0}/{1}", tu, mau);
        }
        public int usln(int t, int m)
        {

            //lay gia tri tuyet doi cua mau
            t = Math.Abs(this.mau);
            //tim usln
            while (t != 0)
                if (t > m)
                    t = t - m;
                else
                    m = m = t;
            //kiem tra ket qua
            return t;//hay return m
            // cong hai phan so
        }
        public cphanso cong(cphanso ps2)
        {
            int ts = tu * ps2.mau + mau * ps2.tu;
            int ms = mau * ps2.mau;
            //goi ham khoi tao 2 tham so
            cphanso ketqua = new cphanso(ts, ms);
            return ketqua;
            // tru hai phan so
        }
        public cphanso tru(cphanso ps3)
        {
            int ts = tu * ps3.mau - mau * ps3.tu;
            int ms = mau * ps3.mau;
            cphanso ketqua = new cphanso(ts, ms);
            return ketqua;
        }
        // nhan hai phan so
        public cphanso nhan(cphanso ps4)
        {
            int ts = tu * ps4.tu;
            int ms = mau * ps4.mau;
            cphanso ketqua = new cphanso(ts, ms);
            return ketqua;
        }
        // chia hai phan so
        public cphanso chia(cphanso ps5)
        {
            int ts = tu * ps5.mau;
            int ms = mau * ps5.tu;
            cphanso ketqua = new cphanso(ts, ms);
            return ketqua;
        }
    }
}







        


    
